package com.hspedu.newData.dmsxl.数组.前缀和;

import org.junit.Test;

import java.util.Arrays;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC724寻找数组的中心下标 {

    // todo 分割子数组和
    public int pivotIndex(int[] nums) {

        int total = Arrays.stream(nums).sum();
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (2*sum + nums[i] == total){
                return i;
            }
            sum += nums[i];
        }
        return -1;
    }


    @Test
    public void test() {
        // 测试代码

        pivotIndex(new int[]{1,7,3,6,5,6});
    }


}
